package api.json.demo001.config;

import apijson.Log;
import apijson.framework.APIJSONApplication;
import apijson.framework.APIJSONCreator;
import apijson.orm.SQLConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class ApiJsonConfig implements CommandLineRunner {

    @Autowired
    private DBSQLConfig dbsqlConfig;

    private static DBSQLConfig SQL_CONFIG;

    @PostConstruct
    public void init() {
        SQL_CONFIG = dbsqlConfig;
    }

    static {
        APIJSONApplication.DEFAULT_APIJSON_CREATOR = new APIJSONCreator<Long>() {
            @Override
            public SQLConfig createSQLConfig() {
                return ApiJsonConfig.SQL_CONFIG;
            }
        };
    }

    @Override
    public void run(String... args) throws Exception {
        Log.DEBUG = false;
        APIJSONApplication.init(false);
    }

}
